package com.codingstudy.login.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.security.Principal;
import java.sql.SQLException;

@Controller
public class ViewController {

    @GetMapping("home")
    public  String index(){
        return "home";
    }

    @RequestMapping(value="/homee", method = RequestMethod.GET)
    public ModelAndView printWelcome(ModelMap model, Principal principal ) throws SQLException {

        ModelAndView mav = new ModelAndView();

            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            String n= auth.getName();
            String r= auth.getAuthorities().toString();

            System.out.println("the value of username is "+n);
            System.out.println("the value of role is  "+r);

            return new ModelAndView();

    }
}
